import { request } from '@umijs/max';
import { PageResponse } from '.';

export interface Quote {
  id: number;
  quote: string;
  source: string;
  famousPersonId: number;
  famousPersonName: string;
  quoteDate?: string;
}

export interface QuotePageRequest {
  pageCurrent: number;
  pageSize: number;
  famousPersonId: number;
  quote?: string;
  source?: string;
  quoteDate?: string;
}

// 分页响应格式

// 后台分页获取语录列表
export async function getQuoteList(pageRequest: QuotePageRequest) {
  return request<PageResponse<Quote>>('/quotes/back/pageList', {
    method: 'POST',
    data: pageRequest,
  });
}

// 前台分页获取语录列表 
export async function getQuoteListFront(pageRequest: QuotePageRequest) {
  return request<PageResponse<Quote>>('/quotes/pageList', {
    method: 'POST',
    data: pageRequest,
  });
}

// 添加语录
export async function addQuote(data: Omit<Quote, 'id'>) {
  return request<Quote>('/quotes/back', {
    method: 'POST',
    data,
  });
}

// 更新语录
export async function updateQuote(data: Quote) {
  return request<Quote>(`/quotes/back`, {
    method: 'PUT',
    data,
  });
}

// 批量删除语录
export async function deleteQuoteBatch(idList: number[]) {
  const ids = idList.join(',');
  return request<void>(`/quotes/back/${ids}`, {
    method: 'DELETE',
  });
} 